<template>
  <div class="hr-container">
    <el-card class="hr-card" shadow="hover">
      <div class="header">
        <div class="title-section">
          <h2 class="page-title">
            <el-icon class="title-icon"><UserFilled /></el-icon>
            人力资源计划表
            <el-tag v-if="projectData.project_name" type="primary" size="small" style="margin-left: 10px;">
              {{ projectData.project_name }}
            </el-tag>
          </h2>
          <p class="description">
            管理项目人员工时分配与工作量权重
            <span v-if="projectData.project_id" style="color: #e6a23c; font-weight: 500;">
              (项目编号: {{ projectData.project_id }})
            </span>
          </p>
        </div>
        <div class="header-actions">
          <el-button v-if="canAdd" type="primary" @click="openDialog()" class="create-btn">
            <el-icon><Plus /></el-icon>
            添加人员
          </el-button>
          <el-button type="primary" @click="saveSettings" class="save-btn" :disabled="!hasPermission">
            <el-icon><Check /></el-icon>
            保存设置
          </el-button>
        </div>
      </div>

      <!-- 项目总工时概览 -->
      <div class="project-summary">
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="summary-item">
              <div class="summary-label">项目总工时 (单位: 小时)</div>
              <div class="summary-value">{{ totalProjectHours }}</div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="summary-item">
              <div class="summary-label">项目剩余工时 (单位: 小时)</div>
              <div class="summary-value">{{ remainingProjectHours }}</div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="summary-item">
              <div class="summary-label">已分配工时 (单位: 小时)</div>
              <div class="summary-value">{{ allocatedHours }}</div>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 人力资源计划表 -->
      <div class="hr-table-container">
        <el-table
          :data="paginatedResourceList"
          stripe
          border
          class="hr-table"
          v-loading="loading"
          empty-text="暂无人力资源计划数据"
        >
          <!-- 序号 -->
          <el-table-column prop="serial" label="序号" width="80" align="center">
            <template #default="scope">
              <span class="serial-number">{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>

          <!-- 姓名 -->
          <el-table-column prop="name" label="姓名" width="150" min-width="120">
            <template #default="scope">
              <div class="member-info">
                <el-avatar :size="28" class="member-avatar">
                  {{ scope.row.name.charAt(0) }}
                </el-avatar>
                <span class="member-name">{{ scope.row.name }}</span>
              </div>
            </template>
          </el-table-column>

          <!-- 项目职责 -->
          <el-table-column prop="role" label="项目职责" width="140" min-width="120">
            <template #default="scope">
              <el-tag :type="getRoleTagType(scope.row.role)" size="small">
                {{ scope.row.role }}
              </el-tag>
            </template>
          </el-table-column>

          <!-- 月度工时列 -->
          <el-table-column 
            v-for="month in months" 
            :key="month.value"
            :label="month.label" 
            :prop="month.value"
            width="120"
            align="center"
            min-width="100"
          >
            <template #default="scope">
              <el-input
                v-model="scope.row[month.value]"
                size="small"
                class="month-hours-input"
                :disabled="!hasPermission"
                @change="handleMonthHoursChange(scope.row, month.value)"
                placeholder="0"
                type="number"
                min="0"
              />
            </template>
          </el-table-column>

          <!-- 个人工时合计 -->
          <el-table-column prop="total_hours" label="个人工时合计 (单位: 小时)" width="150" align="center">
            <template #default="scope">
              <span class="total-hours">{{ calculatePersonTotalHours(scope.row) }}</span>
            </template>
          </el-table-column>

          <!-- 权重分配 -->
          <el-table-column prop="weight_ratio" label="项目人员工作量 权重分配 (n%)" width="150" align="center">
            <template #default="scope">
              <el-input-number
                v-model="scope.row.weight_ratio"
                :min="0"
                :max="100"
                :precision="2"
                :step="0.01"
                size="small"
                style="width: 120px"
                :disabled="!hasPermission"
                @change="handleWeightRatioChange(scope.row)"
                placeholder="0.00"
              />
            </template>
          </el-table-column>

          <!-- 操作列 -->
          <el-table-column label="操作" width="150" fixed="right" v-if="hasPermission">
            <template #default="scope">
              <el-button size="small" type="primary" @click="openDialog(scope.row)">
                <el-icon><Edit /></el-icon>
                编辑
              </el-button>
              <el-button v-if="canAdd" size="small" type="danger" @click="handleDelete(scope.row.id)">
                <el-icon><Delete /></el-icon>
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 月度汇总行 -->
      <div class="monthly-summary">
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="summary-section">
              <h4>月度预计投入人员工时合计 (单位: 小时)</h4>
              <div class="monthly-totals">
                <div v-for="month in months" :key="month.value" class="month-total">
                  <span class="month-label">{{ month.label }}:</span>
                  <span class="month-value">{{ calculateMonthTotalHours(month.value) }}</span>
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="summary-section">
              <h4>项目人员工作量合计</h4>
              <div class="weight-total">
                <span class="weight-label">总权重:</span>
                <span class="weight-value">{{ calculateTotalWeight() }}%</span>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 统计信息 -->
      <div class="hr-stats">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-card class="stat-card">
              <div class="stat-content">
                <div class="stat-number">{{ totalMembers }}</div>
                <div class="stat-label">总人员数</div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="stat-card">
              <div class="stat-content">
                <div class="stat-number">{{ totalWorkHours }}</div>
                <div class="stat-label">总工时(小时)</div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="stat-card">
              <div class="stat-content">
                <div class="stat-number">{{ totalWeightRatio }}%</div>
                <div class="stat-label">总权重比例</div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="stat-card">
              <div class="stat-content">
                <div class="stat-number">{{ averageWorkHours }}</div>
                <div class="stat-label">平均工时</div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 分页组件 -->
      <div class="pagination-container" v-if="resourceList.length > 0">
        <el-pagination
          :current-page="currentPage"
          :page-size="pageSize"
          :page-sizes="[5, 10, 20, 50]"
          :total="resourceList.length"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          @update:current-page="currentPage = $event"
          @update:page-size="pageSize = $event"
          background
          class="hr-pagination"
        />
      </div>
    </el-card>

    <!-- 人员创建/编辑对话框 -->
    <el-dialog
      v-model="dialogVisible"
      :title="form.id ? '编辑人员计划' : '添加人员计划'"
      width="800px"
      align-center
      :close-on-click-modal="false"
    >
      <el-form :model="form" :rules="formRules" ref="formRef" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目编号" prop="project_id">
              <el-input v-model="form.project_id" placeholder="项目编号" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="project_name">
              <el-input v-model="form.project_name" placeholder="项目名称" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="人员姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入人员姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目角色" prop="role">
              <el-select v-model="form.role" placeholder="请选择角色" style="width: 100%">
                <el-option label="项目经理" value="项目经理" />
                <el-option label="开发工程师" value="开发工程师" />
                <el-option label="测试工程师" value="测试工程师" />
                <el-option label="产品经理" value="产品经理" />
                <el-option label="UI设计师" value="UI设计师" />
                <el-option label="资料员" value="资料员" />
                <el-option label="其他人员" value="其他人员" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        
        <!-- 月度工时设置 -->
        <el-form-item label="月度工时设置">
          <div class="monthly-hours-grid">
            <div v-for="month in months" :key="month.value" class="month-input">
              <label>{{ month.label }}</label>
              <el-input-number
                v-model="form[month.value]"
                :min="0"
                :precision="0"
                :step="1"
                size="small"
                style="width: 80px"
                placeholder="0"
              />
            </div>
          </div>
        </el-form-item>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="权重比例" prop="weight_ratio">
              <el-input-number
                v-model="form.weight_ratio"
                :min="0"
                :max="100"
                :precision="2"
                :step="0.01"
                style="width: 100%"
                placeholder="请输入权重比例"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总工时" prop="total_hours">
              <el-input v-model="form.total_hours" placeholder="总工时" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注信息（选填）" />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit" :loading="submitLoading">
          {{ form.id ? '更新' : '创建' }}
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { UserFilled, Plus, Edit, Delete, Check, Search } from '@element-plus/icons-vue'
import { getResourcePlanList, createResourcePlan, updateResourcePlan, deleteResourcePlan, getResourcePlanByProjectId } from '../../api/resourcePlan'

// Props
const props = defineProps({
  projectData: {
    type: Object,
    default: () => ({})
  },
  projectId: {
    type: String,
    default: ''
  }
})

// 获取当前登录用户信息
const currentUser = ref(JSON.parse(localStorage.getItem('user') || '{}'))
const isAdmin = computed(() => currentUser.value.userType === '管理员')

// 检查是否为当前项目的项目经理
const isProjectManager = computed(() => {
  if (!props.projectData || !props.projectData.project_manager) {
    return false
  }
  // 检查当前用户是否为该项目的项目经理
  return currentUser.value.username === props.projectData.project_manager || 
         currentUser.value.userId === props.projectData.project_manager ||
         currentUser.value.id === props.projectData.project_manager
})

// 检查是否有权限操作（只有当前项目的项目经理可以操作）
const hasPermission = computed(() => {
  return isProjectManager.value
})

// 检查是否可以新增和删除（只有当前项目的项目经理可以操作）
const canAdd = computed(() => {
  return isProjectManager.value
})

// 月份配置
const months = ref([
  { label: '1月', value: 'month_1' },
  { label: '2月', value: 'month_2' },
  { label: '3月', value: 'month_3' },
  { label: '4月', value: 'month_4' },
  { label: '5月', value: 'month_5' },
  { label: '6月', value: 'month_6' },
  { label: '7月', value: 'month_7' },
  { label: '8月', value: 'month_8' },
  { label: '9月', value: 'month_9' },
  { label: '10月', value: 'month_10' },
  { label: '11月', value: 'month_11' },
  { label: '12月', value: 'month_12' }
])

// 响应式数据
const resourceList = ref([])
const loading = ref(false)
const submitLoading = ref(false)
const dialogVisible = ref(false)
const formRef = ref()

// 分页相关数据
const currentPage = ref(1)
const pageSize = ref(10)

const form = ref({
  id: null,
  project_id: '',
  project_name: '',
  name: '',
  role: '',
  month_1: 0,
  month_2: 0,
  month_3: 0,
  month_4: 0,
  month_5: 0,
  month_6: 0,
  month_7: 0,
  month_8: 0,
  month_9: 0,
  month_10: 0,
  month_11: 0,
  month_12: 0,
  total_hours: '',
  weight_ratio: 0,
  remark: ''
})

const formRules = {
  project_id: [{ required: true, message: '请输入项目编号', trigger: 'blur' }],
  name: [{ required: true, message: '请输入人员姓名', trigger: 'blur' }],
  role: [{ required: true, message: '请选择项目角色', trigger: 'change' }],
  weight_ratio: [{ required: true, message: '请输入权重比例', trigger: 'blur' }]
}

// 统计计算
const totalMembers = computed(() => {
  return resourceList.value.length
})

const totalWorkHours = computed(() => {
  return resourceList.value.reduce((sum, item) => sum + calculatePersonTotalHours(item), 0)
})

const totalWeightRatio = computed(() => {
  return resourceList.value.reduce((sum, item) => sum + (parseFloat(item.weight_ratio) || 0), 0).toFixed(2)
})

const averageWorkHours = computed(() => {
  if (resourceList.value.length === 0) return 0
  return (totalWorkHours.value / resourceList.value.length).toFixed(1)
})

// 分页后的数据
const paginatedResourceList = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  return resourceList.value.slice(start, end)
})

// 项目工时概览 - 从项目信息获取
const totalProjectHours = computed(() => {
  // 从项目数据中获取总工时，如果没有则使用默认值
  return props.projectData.total_hours || props.projectData.work_hours || 2000
})

const remainingProjectHours = computed(() => {
  return totalProjectHours.value - totalWorkHours.value
})

const allocatedHours = computed(() => {
  return totalWorkHours.value
})

// 获取角色标签样式
function getRoleTagType(role) {
  const roleMap = {
    '项目经理': 'danger',
    '开发工程师': 'primary',
    '测试工程师': 'success',
    '产品经理': 'warning',
    'UI设计师': 'info',
    '资料员': 'success',
    '其他人员': 'info'
  }
  return roleMap[role] || 'info'
}

// 生成GUID
function generateGUID() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    const r = Math.random() * 16 | 0
    const v = c === 'x' ? r : (r & 0x3 | 0x8)
    return v.toString(16)
  })
}

// 计算个人总工时
function calculatePersonTotalHours(person) {
  return months.value.reduce((sum, month) => {
    return sum + (parseInt(person[month.value]) || 0)
  }, 0)
}

// 计算月度总工时
function calculateMonthTotalHours(monthValue) {
  return resourceList.value.reduce((sum, person) => {
    return sum + (parseInt(person[monthValue]) || 0)
  }, 0)
}

// 计算总权重
function calculateTotalWeight() {
  return resourceList.value.reduce((sum, person) => {
    return sum + (parseFloat(person.weight_ratio) || 0)
  }, 0).toFixed(2)
}

// 月度工时变化处理
function handleMonthHoursChange(row, monthValue) {
  // 确保输入的是有效数字
  const value = parseInt(row[monthValue]) || 0
  row[monthValue] = Math.max(0, value) // 确保不为负数
  console.log('月度工时变化:', row.name, monthValue, '新工时:', row[monthValue])
}



// 权重比例变化处理
function handleWeightRatioChange(row) {
  row.weight_ratio = parseFloat(row.weight_ratio) || 0
  console.log('权重比例变化:', row.name, '新权重:', row.weight_ratio)
}

// 分页事件处理
function handleSizeChange(newSize) {
  pageSize.value = newSize
  currentPage.value = 1 // 重置到第一页
  console.log('页面大小改变:', newSize)
}

function handleCurrentChange(newPage) {
  currentPage.value = newPage
  console.log('当前页改变:', newPage)
}

// 加载人力资源计划数据
async function loadResourcePlan() {
  const currentProjectId = props.projectData.project_id || props.projectId
  
  if (currentProjectId) {
    try {
      loading.value = true
      console.log('加载项目人力资源计划，项目ID:', currentProjectId)
      const data = await getResourcePlanByProjectId(currentProjectId)
      
      // 转换数据格式，从work_hours字段解析月度工时数据
      resourceList.value = data.map(item => {
        const newItem = { ...item }
        
        // 尝试从work_hours字段解析月度工时数据
        if (item.work_hours) {
          try {
            const monthlyHours = JSON.parse(item.work_hours)
            if (Array.isArray(monthlyHours)) {
              monthlyHours.forEach(monthData => {
                newItem[monthData.value] = monthData.hours || 0
              })
            }
          } catch (e) {
            console.warn('解析work_hours数据失败:', e)
            // 如果解析失败，可能是旧数据格式，尝试兼容处理
            if (typeof item.work_hours === 'number') {
              // 如果是数字，分配到第一个月
              newItem.month_1 = item.work_hours
            }
          }
        }
        
        // 确保每个月份字段都存在
        months.value.forEach(month => {
          if (!newItem[month.value]) {
            newItem[month.value] = 0
          }
        })
        
        return newItem
      })
      
      console.log('当前项目人力资源计划数量:', resourceList.value.length)
      console.log('人力资源计划数据:', resourceList.value)
    } catch (error) {
      ElMessage.error('加载项目人力资源计划失败')
      console.error('加载项目人力资源计划失败:', error)
      resourceList.value = []
    } finally {
      loading.value = false
    }
  } else {
    resourceList.value = []
    console.log('没有项目编号，不加载项目人力资源计划')
  }
}

// 打开对话框
function openDialog(resource = null) {
  if (resource) {
    form.value = { ...resource }
  } else {
    form.value = {
      id: null,
      project_id: props.projectData.project_id || props.projectId || '',
      project_name: props.projectData.project_name || '',
      name: '',
      role: '',
      month_1: 0,
      month_2: 0,
      month_3: 0,
      month_4: 0,
      month_5: 0,
      month_6: 0,
      month_7: 0,
      month_8: 0,
      month_9: 0,
      month_10: 0,
      month_11: 0,
      month_12: 0,
      total_hours: '',
      weight_ratio: 0,
      remark: '',
      work_hours: ''
    }
  }
  dialogVisible.value = true
}

// 提交表单
async function handleSubmit() {
  if (!formRef.value) return
  
  try {
    await formRef.value.validate(async (valid) => {
      if (!valid) return
      
      submitLoading.value = true
      
      // 计算总工时
      form.value.total_hours = calculatePersonTotalHours(form.value).toString()
      
      // 将月度工时数据序列化为数组存储到work_hours字段
      const monthlyHours = months.value.map(month => ({
        month: month.label,
        value: month.value,
        hours: parseInt(form.value[month.value]) || 0
      }))
      
      // 将月度数据存储到work_hours字段
      form.value.work_hours = JSON.stringify(monthlyHours)
      
      if (!form.value.id) {
        const payload = { ...form.value }
        payload.id = generateGUID()
        console.log('创建人力资源计划，payload:', payload)
        await createResourcePlan(payload)
        ElMessage.success('人力资源计划添加成功')
      } else {
        console.log('更新人力资源计划，payload:', form.value)
        await updateResourcePlan(form.value.id, form.value)
        ElMessage.success('人力资源计划更新成功')
      }
      
      dialogVisible.value = false
      loadResourcePlan()
    })
  } catch (error) {
    ElMessage.error('操作失败，请重试')
    console.error('提交失败:', error)
  } finally {
    submitLoading.value = false
  }
}

// 删除人力资源计划
function handleDelete(id) {
  ElMessageBox.confirm('确认删除该人力资源计划？此操作不可恢复', '警告', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    try {
      await deleteResourcePlan(id)
      ElMessage.success('删除成功')
      loadResourcePlan()
    } catch (error) {
      ElMessage.error('删除失败，请重试')
      console.error('删除失败:', error)
    }
  }).catch(() => {})
}

// 保存设置
async function saveSettings() {
  try {
    loading.value = true
    
    // 批量保存所有修改的人力资源计划（包括所有页面的数据）
    const savePromises = resourceList.value.map(async (resource) => {
      // 将月度工时数据序列化为数组存储到work_hours字段
      const monthlyHours = months.value.map(month => ({
        month: month.label,
        value: month.value,
        hours: parseInt(resource[month.value]) || 0
      }))
      
      const updateData = {
        ...resource,
        work_hours: JSON.stringify(monthlyHours),
        total_hours: calculatePersonTotalHours(resource).toString()
      }
      
      if (resource.id) {
        return updateResourcePlan(resource.id, updateData)
      }
    })
    
    await Promise.all(savePromises.filter(Boolean))
    ElMessage.success('设置保存成功')
    console.log('批量保存人力资源计划完成')
  } catch (error) {
    ElMessage.error('保存失败，请重试')
    console.error('保存失败:', error)
  } finally {
    loading.value = false
  }
}

// 监听项目数据变化
watch(() => props.projectData, (newProjectData) => {
  if (newProjectData && newProjectData.project_id) {
    if (dialogVisible.value && !form.value.project_id) {
      form.value.project_id = newProjectData.project_id
      form.value.project_name = newProjectData.project_name
    }
    loadResourcePlan()
  }
}, { deep: true })

// 监听项目ID变化
watch(() => props.projectId, (newProjectId) => {
  if (newProjectId) {
    console.log('项目ID变化，重新加载项目人力资源计划:', newProjectId)
    loadResourcePlan()
  }
})

onMounted(() => {
  try {
    loadResourcePlan()
  } catch (error) {
    console.error('人力资源计划页面初始化失败:', error)
  }
})
</script>

<style scoped>
.hr-container {
  padding: 20px;
  background: #f5f7fa;
  min-height: calc(100vh - 120px);
}

.hr-card {
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #ebeef5;
}

.title-section {
  flex: 1;
}

.page-title {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-icon {
  font-size: 24px;
  color: #409eff;
}

.description {
  margin: 0;
  font-size: 14px;
  color: #909399;
  line-height: 1.5;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.create-btn, .save-btn {
  padding: 12px 20px;
  font-weight: 500;
  border-radius: 8px;
}

.project-summary {
  margin-bottom: 20px;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  color: white;
}

.summary-item {
  text-align: center;
}

.summary-label {
  font-size: 14px;
  margin-bottom: 8px;
  opacity: 0.9;
}

.summary-value {
  font-size: 24px;
  font-weight: bold;
}

.summary-value-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 40px;
}

.hr-table-container {
  margin-bottom: 30px;
  overflow-x: auto;
}

.hr-table {
  min-width: 1200px;
  border-radius: 8px;
  overflow: hidden;
}

.serial-number {
  font-weight: 600;
  color: #409eff;
}

.member-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.member-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
}

.member-name {
  font-weight: 500;
  color: #303133;
}

.month-hours-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.monthly-summary {
  margin: 20px 0;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.summary-section h4 {
  margin: 0 0 15px 0;
  color: #303133;
  font-size: 16px;
}

.monthly-totals {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.month-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: white;
  border-radius: 4px;
  border: 1px solid #e4e7ed;
}

.month-label {
  font-size: 12px;
  color: #606266;
}

.month-value {
  font-weight: 600;
  color: #409eff;
}

.weight-total {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px;
  background: white;
  border-radius: 4px;
  border: 1px solid #e4e7ed;
}

.weight-label {
  font-size: 14px;
  color: #606266;
}

.weight-value {
  font-size: 18px;
  font-weight: bold;
  color: #409eff;
}

.hr-stats {
  margin-top: 20px;
}

.stat-card {
  text-align: center;
  border-radius: 8px;
}

.stat-content {
  padding: 20px;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  color: #409eff;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  color: #606266;
}

.monthly-hours-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 15px;
  margin-top: 10px;
}

.month-input {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.month-input label {
  font-size: 12px;
  color: #606266;
  text-align: center;
}

:deep(.el-table) {
  border-radius: 8px;
}

:deep(.el-table th) {
  background: #f5f7fa !important;
  font-weight: 600;
}

:deep(.el-table td) {
  padding: 8px 0;
}

:deep(.el-input-number .el-input__inner) {
  text-align: center;
}

.month-hours-input {
  width: 100px !important;
  min-width: 100px;
}

.month-hours-input :deep(.el-input__inner) {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  border-radius: 8px;
  border: 2px solid #e4e7ed;
  padding: 8px 12px;
  height: 40px;
  transition: all 0.3s ease;
  background: #fafbfc;
}

.month-hours-input :deep(.el-input__inner:hover) {
  border-color: #409eff;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.1);
}

.month-hours-input :deep(.el-input__inner:focus) {
  border-color: #409eff;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.2);
  transform: translateY(-1px);
}

.month-hours-input :deep(.el-input__inner:disabled) {
  background: #f5f7fa;
  color: #c0c4cc;
  cursor: not-allowed;
}

.total-hours {
  font-weight: 600;
  color: #409eff;
  font-size: 14px;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  padding: 20px 0;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.hr-pagination {
  --el-pagination-bg-color: #ffffff;
  --el-pagination-border-radius: 6px;
}

.hr-pagination :deep(.el-pagination__total) {
  font-weight: 500;
  color: #606266;
}

.hr-pagination :deep(.el-pagination__sizes) {
  margin-right: 16px;
}

.hr-pagination :deep(.el-pager li) {
  border-radius: 4px;
  transition: all 0.3s;
}

.hr-pagination :deep(.el-pager li:hover) {
  background-color: #409eff;
  color: #ffffff;
}

.hr-pagination :deep(.el-pager li.is-active) {
  background-color: #409eff;
  color: #ffffff;
}
</style> 